//
//  FavoriteViewController.m
//  ios_news
//
//  Created by Han on 14-7-22.
//  Copyright (c) 2014年 ucoder. All rights reserved.
//

#import "FeedbackViewController.h"
#import "Util.h"

@implementation FeedbackViewController


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.navigationController.navigationBarHidden = NO;
    self.view.backgroundColor = ColorWithRGB(236, 236, 236);
    self.navigationController.navigationBar.barTintColor = MAIN_COLOR;
    self.navigationController.navigationBar.translucent = NO;  // 半透明
    
    self.navigationItem.title = @"意见反馈";
    self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
    [self addButton];

    
    mContextTextView = [[UITextView alloc] initWithFrame:CGRectMake(10, 10, 300, 150)];
    mContextTextView.layer.borderColor = ColorWithRGB(236, 236, 236).CGColor;
    mContextTextView.layer.borderWidth = 1.0;
    mContextTextView.layer.cornerRadius = 5.0;
    
    mContextTextView.text = @"您的意见~";
    mContextTextView.textColor = ColorWithRGB(236, 236, 236);
    mContextTextView.delegate = self;
    
    [self.view addSubview:mContextTextView];
    
    
    mEmailTextView = [[UITextView alloc] initWithFrame:CGRectMake(10, 170, 300, 30)];
    mEmailTextView.layer.borderColor = ColorWithRGB(236, 236, 236).CGColor;
    mEmailTextView.layer.borderWidth = 1.0;
    mEmailTextView.layer.cornerRadius = 5.0;
    
    mEmailTextView.text = @"您的邮箱:选填，以便我们给您答复";
    mEmailTextView.textColor = ColorWithRGB(236, 236, 236);
    
    mEmailTextView.delegate = self;
    
    [self.view addSubview:mEmailTextView];
    
    
    /*
    UITextField *emailTextView = [[UITextField alloc] initWithFrame:CGRectMake(10, 170, 300, 30)];
    emailTextView.backgroundColor = [UIColor whiteColor];
    //[emailTextView setBorderStyle:UITextBorderStyleRoundedRect];
    emailTextView.layer.borderColor = ColorWithRGB(236, 236, 236).CGColor;
    emailTextView.layer.borderWidth = 1.0;
    emailTextView.layer.cornerRadius = 5.0;
    
    emailTextView.placeholder = @"您的邮箱~";
    
    
    [self.view addSubview:emailTextView];
     
     */
}


-(void)textViewDidBeginEditing:(UITextView *)textView {
    
    if ([textView.text isEqualToString:@"您的意见~"]) {
        
        textView.text = @"";
        
    }
    
    [textView becomeFirstResponder];
    
}

- (void)textViewDidEndEditing:(UITextView *)textView

{
    
    if ([textView.text isEqualToString:@""]) {
        
        textView.text = @"您的意见~";
        
        
    }
    
    [textView resignFirstResponder];
    
}

// return键隐藏键盘
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }
    return YES;
}


//添加按钮
-(void)addButton
{
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.exclusiveTouch = YES;
    leftButton.frame = CGRectMake(0, 0, 44, 44);
    //button.backgroundColor = [UIColor redColor];
    
    [leftButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    leftButton.imageEdgeInsets = UIEdgeInsetsMake(0, -30, 0, 0);
    
    [leftButton addTarget:self action:@selector(backButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = leftButtonItem;
    
    
    //编辑 搜索按钮
    mSendButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
    mSendButton.exclusiveTouch = YES;
    [mSendButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [mSendButton setTitle:@"发送" forState:UIControlStateNormal];
    [mSendButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [mSendButton setBackgroundColor:[UIColor clearColor]];
    [mSendButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:mSendButton];
    self.navigationItem.rightBarButtonItem = rightItem;
    
}

-(void) buttonClicked:(id)sender
{
    [Util showMess:@"检测中..." inView:self.view];
    [Util dissmissProcessInView:self.view];
    [Util dismissSuccess:@"反馈成功" inView:self.view];
}

-(void)backButtonClicked:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}




@end
